package com.hundsun.cprs.yyt.service.system.service.impl;

import java.util.List;

import com.hundsun.cprs.yyt.common.base.BaseService;
import com.hundsun.cprs.yyt.common.exception.ServiceCodeException;
import com.hundsun.cprs.yyt.service.rabbit.RoutingKeyConstants;
import com.hundsun.cprs.yyt.service.system.dao.BussinessParamDao;
import com.hundsun.cprs.yyt.service.system.domain.BussinessParam;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.hundsun.cprs.yyt.common.base.BaseService;
import com.hundsun.cprs.yyt.common.exception.ServiceCodeException;
import com.hundsun.cprs.yyt.service.system.dao.BussinessParamDao;
import com.hundsun.cprs.yyt.service.system.domain.BussinessParam;
import com.hundsun.cprs.yyt.service.system.domain.query.BussinessParamQuery;
import com.hundsun.cprs.yyt.service.system.service.BussinessParamService;
@Service
public class BussinessParamServiceImpl extends BaseService implements BussinessParamService {
	@Autowired
	private BussinessParamDao bussinessParamDao;
	
    @Autowired
    private RabbitTemplate rabbitTemplate;
	
	@Override
	public List<BussinessParam> queryBussinessParamList(BussinessParamQuery query) {
		return bussinessParamDao.queryBussinessParamList(query);
	}

	@Override
	@CacheEvict(value = "YYT:SystemParamInfoCache:key",key="new String(#bussinessParam.bussinessKey)")
	public void updateBussinessParamValue(BussinessParam bussinessParam) throws ServiceCodeException {
	    bussinessParamDao.updateBussinessParamValue(bussinessParam);
	    
		BussinessParam updateParam = bussinessParamDao.selectByPrimaryKey(bussinessParam.getId());
		//发送系统参数变更通知,让感兴趣的模块监听
		rabbitTemplate.convertAndSend(RoutingKeyConstants.YYT_SYSTEM_PARAM_CHANGE,updateParam);
	}

	@Override
	@Cacheable(value = "YYT:SystemParamInfoCache:key",key="new String(#bussinessKey)")
	public BussinessParam getBussinessParamByKey(String bussinessKey) {
		return bussinessParamDao.getBussinessParamByKey(bussinessKey);
	}

}
